import { useReducer } from "react";
const useMyReducer = () => {
    const initState = {
        count: 0
    }
    const reducer = (state, action) => {
        // action相当于vuex的action
        switch (action.type) {
            case "increase":
                return { count: state.count + 1 }
            case "decrease":
                return { count: state.count - 1 }
            default:
                return initState
        }
    }
    // dispatch相当于vuex
    const [state, dispatch] = useReducer(reducer, initState)
    return [state, dispatch]
}

export default useMyReducer